package com.hundsun.cprs.yyt.service.goods.domain;

import com.hundsun.cprs.yyt.common.base.DomainBase;

public class GoodsSpecs extends DomainBase{
    private Long id;
    
    private String areaCode;//区编码

    private Integer goodsId;
    
    private String plateCode;//专场编码

    private String goodsSpecs;//规格

    private Integer goodsStock;//库存

    private Double goodsPrice;//折扣价

    private Integer quotaAmount;//购买所需配额

    private Long version=0L;//版本控制

    private Integer allocatedStock;//预占库存
    
    /**
     * 父SKU
     */
    private GoodsSpecs parent;
    
    /**
     * 冻结库存
     */
    private Integer frozenStock;
    
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public Integer getGoodsId() {
        return goodsId;
    }

    public void setGoodsId(Integer goodsId) {
        this.goodsId = goodsId;
    }

    public String getGoodsSpecs() {
        return goodsSpecs;
    }

    public void setGoodsSpecs(String goodsSpecs) {
        this.goodsSpecs = goodsSpecs == null ? null : goodsSpecs.trim();
    }

    public Integer getGoodsStock() {
        return goodsStock;
    }

    public void setGoodsStock(Integer goodsStock) {
        this.goodsStock = goodsStock;
    }

    public Double getGoodsPrice() {
        return goodsPrice;
    }

    public void setGoodsPrice(Double goodsPrice) {
        this.goodsPrice = goodsPrice;
    }

    public Integer getQuotaAmount() {
        return quotaAmount;
    }

    public void setQuotaAmount(Integer quotaAmount) {
        this.quotaAmount = quotaAmount;
    }

    public Long getVersion() {
        return version;
    }

    public void setVersion(Long version) {
        this.version = version;
    }

    public Integer getAllocatedStock() {
        return allocatedStock;
    }

    public void setAllocatedStock(Integer allocatedStock) {
        this.allocatedStock = allocatedStock;
    }

    public String getAreaCode() {
        return areaCode;
    }

    public void setAreaCode(String areaCode) {
        this.areaCode = areaCode;
    }

    public String getPlateCode() {
        return plateCode;
    }

    public void setPlateCode(String plateCode) {
        this.plateCode = plateCode;
    }
    
    public Integer getFrozenStock() {
        return frozenStock;
    }

    public void setFrozenStock(Integer frozenStock) {
        this.frozenStock = frozenStock;
    }

    public GoodsSpecs getParent() {
        return parent;
    }

    public void setParent(GoodsSpecs parent) {
        this.parent = parent;
    }
    
    /**
     * 获取可售库存
     * @return
     */
    public int getAvailableStock(){
        GoodsSpecs parentSku = getParent();
        int availableStock = 0;
        if (parentSku != null) {
            //若SKU有父级，说明本SKU是个映射SKU，取父SKU的可售库存(排查冻结库存)展示
            availableStock = parentSku.getAvailableStockWithoutFrozen();
        } else {
            int goodsStock = getGoodsStock() == null?0:getGoodsStock();
            int allocatiedStock = getAllocatedStock() == null?0:getAllocatedStock();
            int frozenStock = getFrozenStock() == null?0:getFrozenStock();
            availableStock = goodsStock - allocatiedStock - frozenStock;
        }
        return availableStock < 0?0:availableStock;
    }
    
    /**
     * 获取可售库存(不包含冻结库存)
     * @return
     */
    protected int getAvailableStockWithoutFrozen(){
        int goodsStock = getGoodsStock() == null?0:getGoodsStock();
        int allocatiedStock = getAllocatedStock() == null?0:getAllocatedStock();
        int availableStock = goodsStock - allocatiedStock;
        return availableStock < 0?0:availableStock; 
    }
}